function validate() {
    var element;
    var error = "";
    element = document.getElementsByName("fromDate")[0];
    if (validateDate(element) == false) {
        error = error + "From Date format is wrong!";
    }
    element = document.getElementsByName("toDate")[0];
    if (validateDate(element) == false) {
        error = error + "To Date format is wrong!";
    }
    if (error) {
        return false;
    } else {
        return true;
    }
}

window.onload = function() {
    var fromYearValue = document.getElementById("fromYearValue").value;
    var toYearValue = document.getElementById("toYearValue").value;
    selectStatus("fromYear", fromYearValue);
    selectStatus("toYear", toYearValue);
}

function selectStatus(selectId, status) {
    var selectElem = document.getElementsByName(selectId)[0];
    if (selectElem && status) {
        var options;
        var option;
        var size;
        options = selectElem.options;
        size = options.length;
        for (var i = 0; i < size; i++) {
            option = options[i];
            if (option.value == status) {
                option.selected = true;
                break;
            }
        }
    }
}
function validateDate(element) {
    var value;
    var tokens;
    if (element) {
        value = element.value;
        tokens = value.split("-/ ");
        try {
            // format dd/mm/yyyy
            new Date(tokens[2], tokens[1], tokens[0]);
        } catch (e) {
            return false;
        }
    }
    return true;
}